﻿#region usings
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Media;
using Papa.Common;
using InsuranceAdjuster.Services;
#endregion

namespace InsuranceAdjuster.Models {
    public class BranchStyle : NotifiableObject {
        #region Initializing
        Services.IInsuranceAdjusterDataService _serviceProvider;
        public BranchStyle() {
            // Set some default values
            this.HeadingBackgroundBrush = ColorConverter.GetColorFromHex("#FFFFC800");
            this.HeadingForegroundBrush = ColorConverter.GetColorFromHex("#FF625F55");
            this.BackgroundBrush = ColorConverter.GetColorFromHex("#FFFFC800");
            this.ForegroundBrush = ColorConverter.GetColorFromHex("#FF625F55");
            this.BranchFont = "Segoe";
            // Kick off an async load of branch styles
            // Grab the dataService from the ServiceProviderBase, 
            // as it instances the design/runtime services
            _serviceProvider = Services.ServiceProviderBase.Instance.InsuranceAdjusterDataService;
        }
        #endregion

        public void Load() {

            // Get the custom styles
            _serviceProvider.GetBranchStyles(GetBranchStylesCallback);
        }

        private void GetBranchStylesCallback(Models.BranchStyle branchStyle) {
            // Copy the values from the returned serialzied server instance
            this.HeadingForegroundBrush = branchStyle.HeadingForegroundBrush;
            this.HeadingBackgroundBrush = branchStyle.HeadingBackgroundBrush;
            this.ForegroundBrush = branchStyle.HeadingForegroundBrush;
            this.BackgroundBrush = branchStyle.HeadingBackgroundBrush;
            this.BranchFont = branchStyle.BranchFont;
        }

        #region Bindable Properties

        private SolidColorBrush _backgroundBrush;
        public SolidColorBrush BackgroundBrush {
            get { return _backgroundBrush; }
            set {
                if (value != _backgroundBrush) {
                    _backgroundBrush = value;
                    RaisePropertyChanged("BackgroundBrush");
                }
            }
        }

        private SolidColorBrush _foregroundBrush;
        public SolidColorBrush ForegroundBrush {
            get { return _foregroundBrush; }
            set {
                if (value != _foregroundBrush) {
                    _foregroundBrush = value;
                    RaisePropertyChanged("ForegroundBrush");
                }
            }
        }
        

        private SolidColorBrush _headingBackgroundBrush;
        public SolidColorBrush HeadingBackgroundBrush {
            get { return _headingBackgroundBrush; }
            set {
                if (value != _headingBackgroundBrush) {
                    _headingBackgroundBrush = value;
                    RaisePropertyChanged("HeadingBackgroundBrush");
                }
            }
        }

        private SolidColorBrush _headingForegroundBrush;
        public SolidColorBrush HeadingForegroundBrush {
            get { return _headingForegroundBrush; }
            set {
                if (value != _headingForegroundBrush) {
                    _headingForegroundBrush = value;
                    RaisePropertyChanged("HeadingForegroundBrush");
                }
            }
        }

        private string _branchFont;
        public string BranchFont {
            get { return _branchFont; }
            set {
                if (value != _branchFont) {
                    _branchFont = value;
                    RaisePropertyChanged("BranchFont");
                }
            }
        }
        #endregion
    }
}
